package com.selune.online.ordering.system.project.tenant.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.selune.online.ordering.system.project.api.base.response.Response;
import com.selune.online.ordering.system.project.api.pojo.order.dto.OrderSearchDTO;
import com.selune.online.ordering.system.project.api.pojo.order.vo.OrderOverviewVO;
import com.selune.online.ordering.system.project.api.service.tenant.ITenantOrderService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 商户订单控制器
 *
 * @author : xiaoyp
 * @date : 2020/02/20
 */

@RestController
@RequestMapping("/api/v1/ordering/tenant/order")
@Slf4j
public class TenantOrderController {
	
	@Autowired
	private ITenantOrderService iTenantOrderService;
	
	@ApiOperation(value = "完成订单", notes = "完成订单")
	@ApiImplicitParam(name = "orderId", value = "订单id", dataType = "orderId", paramType = "query")
	@PutMapping(value = "/finish/{orderId}", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<Boolean> finishOrder(@PathVariable("orderId") Long orderId) {
		return iTenantOrderService.finishOrder(orderId);
	}
	
	@ApiOperation(value = "订单分页", notes = "订单分页")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "current", value = "当前页", required = true, dataType = "Integer", paramType = "query"),
		@ApiImplicitParam(name = "size", value = "页大小", dataType = "Integer", paramType = "query"),
		@ApiImplicitParam(name = "orderSearchDTO", value = "订单查询条件", dataType = "OrderSearchDTO", paramType = "query")
	})
	@GetMapping(value = "/page", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<Page<OrderOverviewVO>> listOrder(Integer current, Integer size,
	                                                 OrderSearchDTO orderSearchDTO) {
		return iTenantOrderService.listOrder(current, size, orderSearchDTO);
	}
}
